import axios from 'axios'
// @ts-ignore
import {getToken} from "@/utils/auth";


const env = import.meta.env
console.log(env)
export const baseURL = ''

const service = axios.create({
    // baseURL: '/api',
    baseURL: baseURL,
    timeout: 50000
})

// 请求拦截: 每一次发请求都会做的事情
service.interceptors.request.use(
    config => {
        const token = getToken() as string
        if (token) {
            config.headers!['Authorization'] = `Bearer ${token}`;
        }


        return config
    },
    error => {
        return Promise.reject(error)
    }
)


//响应拦截
service.interceptors.response.use((response) => {
    return response.data
}, (err) => {
    console.log(err)

    return Promise.reject(err)
})

export default service
